package com.example.lib_core.task

/**
 * 任务工具类
 */
class Task {

    companion object {

        var ANDROID_PLATFORM = true


        /**
         * 创建结果任务
         */
        fun <T> singleTask(runnable: (SingleTask<*>) -> T): SingleTask<T> {
            return object : SingleTask<T>() {

                @Throws(Exception::class)
                override fun onTaskRun(): T {
                    return runnable(this)
                }
            }
        }

        /**
         * 创建进度任务
         */
        fun <P, R> progressTask(runnable: (ProgressTask<P, R>) -> R): ProgressTask<P, R> {
            return object : ProgressTask<P, R>() {

                @Throws(Exception::class)
                override fun onTaskRun(): R {
                    return runnable(this)
                }
            }
        }

        /**
         * 创建定时器
         */
        fun timerTask(initialDelay: Long = 10,
                      interval: Long = 1000,
                      action: (timer: TimerTask, tick: TimerTask.Tick) -> Unit): TimerTask {

            return TimerTask(initialDelay, interval, action)
        }
    }
}